package src.domain;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Version;

//import org.hibernate.annotations.Cascade;
//import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import src.common.MessageStatus;

@Entity
public class IncomingMessage implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Long id;
	private int version;
	private OutgoingMessage outgoingMessage;
	private MessageStatus messageStatus;
	
	public IncomingMessage(){}
	
	/*public IncomingMessage(IncomingMessageDTO incomingMessageDTO){
		this.id=incomingMessageDTO.getId();
		this.version=incomingMessageDTO.getVersion();
		this.messageStatus=incomingMessageDTO.getMessageStatus();
		this.outgoingMessage=new OutgoingMessage(incomingMessageDTO.getOutgoingMessage());
	}*/
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	
	public void setId(Long id) {
		this.id = id;
	}

	@Version
	public int getVersion() {
		return version;
	}
	
	public void setVersion(int version) {
		this.version = version;
	}
	
	@ManyToOne
	@Fetch(FetchMode.JOIN)
	@JoinColumn(name="idOutgoingMessage")
	public OutgoingMessage getOutgoingMessage() {
		return outgoingMessage;
	}
	public void setOutgoingMessage(OutgoingMessage outgoingMessage) {
		this.outgoingMessage = outgoingMessage;
	}
	
	@Enumerated(EnumType.STRING)
	public MessageStatus getMessageStatus() {
		return messageStatus;
	}
	public void setMessageStatus(MessageStatus messageStatus) {
		this.messageStatus = messageStatus;
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		IncomingMessage other = (IncomingMessage) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	
	
	
}
